package ee.rsi2m.goproject.model;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

public class GoGroup {

	private int lifePoints;
	private List<GoStone> stones;

	public GoGroup() {
		stones = new ArrayList<GoStone>();
	}

	public void addStone(GoStone stone) {
		stones.add(stone);
	}

	public int getSize() {
		return stones.size();
	}

	public List<GoStone> getStones() {
		return stones;
	}

	public void addStones(List<GoStone> list) {
		stones.addAll(list);
	}

	// DEBUG
	public void printAllStoneCoord() {
		for (GoStone stone : stones) {
			Log.w("Groups",
					"X:" + stone.getRelativeX() + "Y:" + stone.getRelativeY());
		}
	}

	public void addLifePoints(int points) {
		Log.w("Friend","addLifePoints is called with attribute points:"+points);
		lifePoints = lifePoints + points;
		if (lifePoints < 1) {
			this.delete();
		}
	}

	public void decreaseLifePoints(int points) {
		Log.w("Friend","decreaseLifePoints is called with attribute points:"+points);
		lifePoints = lifePoints - points;
		Log.w("LifePoints", "Amount of them:" + lifePoints);
		if (lifePoints < 1) {
			
			this.delete();
			if(this.stones.size() == 1)
				stones.get(0).setKo(true);
		}
	}

	public void delete() {
		for (GoStone stone : stones) {
			Log.w("Enemy", "MUTTAFUCKA!");
			stone.setVisibility(false);
		}

	}

	@Override
	public String toString() {
		if (this.stones.size() > 0) {
			return "Group with size:" + this.stones.size() + ",Lifepoints:"
					+ this.lifePoints + ",first stone rel. coords:{X:"
					+ this.stones.get(0).getRelativeX() + ";Y:"
					+ this.stones.get(0).getRelativeY()+"}";
		}
		else{
			return "Empty group";
		}
	}

	public void setLifePoints(int lifePoints) {
		Log.w("Friend","setLifePoints is called with attribute lifepoints:"+lifePoints);
		this.lifePoints = lifePoints;
	}

	public int getLifePoints() {
		return lifePoints;
	}

	public void flushLifePoints() {
		this.lifePoints=0;
		
	}
	
	

}
